// 商品相关的请求
import service from "./index";
const prifex = "/goods";

// 更新商品信息
export function update(goods) {
  return service({
    url: `${prifex}/update`,
    method: "PUT",
    data: goods,
  });
}
// 新增商品信息
export function addGoods(addGoods) {
  return service({
    url: `${prifex}/addGoods`,
    method: "POST",
    data: addGoods,
  });
}

// 根据id查询商品信息
export function getById(id) {
  return service({
    url: `${prifex}/getById/${id}`,
    method: "GET",
  });
}

// 分页查询商品信息
export function pageList(pageInfo, pageListReq) {
  const params = {};
  if (pageInfo) {
    params.pageNum = pageInfo.pageNum;
    params.pageSize = pageInfo.pageSize;
  }
  if (pageListReq) {
    params.assort = pageListReq.assort;
    params.name = pageListReq.name;
    params.accessoryName = pageListReq.accessoryName;
  }

  return service({
    url: `${prifex}/pageList`,
    method: "GET",
    params: params,
  });
}

// 根据商品id删除商品信息
export function deleteById(id) {
  return service({
    url: `${prifex}/deleteById/${id}`,
    method: "DELETE",
  });
}

// 根据商品id修改商品信息
export function updateById(updateGoodsReq) {
  return service({
    url: `${prifex}/updateById`,
    method: "PUT",
    data: updateGoodsReq,
  });
}

/**
 * 查询商品信息
 */
export function selectGoods(searchValue) {
  return service({
    url: `${prifex}/selectGoods`,
    method: "GET",
    params: {
      searchValue: searchValue,
    },
  });
}
